package singleton;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by User on 2017/12/13.
 */
public class App {


    public static void main(String[] args) {
        Random random = new Random();

        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; i++) {
            pool.submit(() -> {
                for (;;) {
                    Singleton singleton = Singleton.getSingleton();
                    if (singleton == null) {
                        System.out.println("error");
                    }
                    int i1 = random.nextInt(10);
                    Thread.sleep(i1);
                }
            });
        }

        pool.submit(()->{
            for(;;) {
                Singleton.destroy();
                int i1 = random.nextInt(10);
                Thread.sleep(i1);
            }
        });

    }
}
